package com.sikaryofficial.backend.controller.music;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sikaryofficial.backend.domain.dto.req.music.MusicLibraryListReq;
import com.sikaryofficial.backend.domain.dto.resp.music.MusicGenreVO;
import com.sikaryofficial.backend.domain.dto.resp.music.MusicLibraryDTO;
import com.sikaryofficial.backend.manager.information.MusicLibraryManager;
import com.sikaryofficial.common.core.domain.R;
import com.sikaryofficial.common.core.utils.PageUtil;
import com.sikaryofficial.common.core.web.controller.BaseController;
import com.sikaryofficial.common.core.web.domain.PageResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 音乐Controller
 *
 * @author qinjinyuan
 * @date 2024-08-07
 */
@RestController
@RequestMapping("/musicLibrary/frontend")
@Api(tags = "V3.5.1-音乐库H5")
@Slf4j
public class MusicLibraryFrontendController extends BaseController {
    @Autowired
    private MusicLibraryManager musicLibraryManager;

    /**
     * H5 发布短视频，需要查询音乐库
     */
    @GetMapping("/musicGenreList")
    @ApiOperation("H5-音乐分类列表")
    public R<List<MusicGenreVO>> musicGenreList() {
        return R.ok(musicLibraryManager.musicGenreList());
    }

    /**
     * H5 发布短视频，需要查询音乐库
     */
    @PostMapping("/listPage")
    @ApiOperation("H5查询音乐库分页列表")
    public PageResult<MusicLibraryDTO> listPage(@Validated @RequestBody MusicLibraryListReq req) {
        // 查询获奖列表
        IPage<MusicLibraryDTO> page = musicLibraryManager.listPageForCache(req);
        return PageUtil.success(page.getRecords(), page.getTotal());
    }
}
